package org.dromara.report.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.components.date.DateComponent;
import org.dromara.report.order.domain.bo.ReportOrderQueryBo;
import org.springframework.stereotype.Service;
import org.dromara.report.order.domain.bo.ReportConsumeOrderTotalBo;
import org.dromara.report.order.domain.vo.ReportConsumeOrderTotalVo;
import org.dromara.report.order.mapper.ReportOrderMapper;
import org.dromara.report.order.service.IReportOrderService;

import java.util.Map;

/**
 * 报表-消费订单汇总Service业务层处理
 *
 * @author wdm
 * @date 2024-03-01
 */
@RequiredArgsConstructor
@Service
@Slf4j
public class ReportOrderServiceImpl implements IReportOrderService {

    private final ReportOrderMapper baseMapper;

    private LambdaQueryWrapper<ReportOrderQueryBo> buildQueryWrapper(ReportConsumeOrderTotalBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportOrderQueryBo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getStoreId() != null, ReportOrderQueryBo::getStoreId, bo.getStoreId());
       lqw.between(params.get("beginOrderTime") != null && params.get("endOrderTime") != null,
           ReportOrderQueryBo::getOrderTime ,params.get("beginOrderTime"), params.get("endOrderTime"));
        return lqw;
    }

    /**
     * 查询报表-消费订单汇总列表
     */
    @Override
    public TableDataInfo<ReportConsumeOrderTotalVo> queryConsumeOrderPageList(ReportConsumeOrderTotalBo bo, PageQuery pageQuery) {
        DateComponent.setQueryTimeRange(bo.getQueryTimeRange(),bo,"beginOrderTime","endOrderTime");
        Page<ReportConsumeOrderTotalVo> result = baseMapper.queryConsumeOrderPageList(pageQuery.build(), bo);
        return TableDataInfo.build(result);
    }

}
